﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Webbshop
{
    public partial class Orders : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                gridOrders.DataSource = Functions.GetOrders(MyProfile.GetProfile().UserName);
                gridOrders.DataBind();

                // Gör DetailsView synlig och visa upp ett meddelande
                DetailsView1.DataSource = new List<Product>();
                DetailsView1.DataBind();
                var lbl = DetailsView1.Controls[0].Controls[1].Controls[0].Controls[0].FindControl("lblNoData") as Literal;
                if (Request.Cookies["Culture"].Value == "sv-SE")
                    lbl.Text = "Vänligen välj en Order.";
                else
                    lbl.Text = "Please choose an Order.";
            }
        }

        /// <summary>
        /// Event när en användare tryckt på en av raderna
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void gridOrders_SelectedIndexChange(object source, EventArgs e)
        {
                var orderId = int.Parse(gridOrders.Rows[gridOrders.SelectedIndex].Cells[0].Text);
                DetailsView1.DataSource = Functions.GetOrderDetail(orderId);
                DetailsView1.DataBind();
        }
    }
}